package com.trafficsys.util;

import com.zhenzi.sms.ZhenziSmsClient;

import java.util.HashMap;
import java.util.Map;

public class ZhenziSmsUtil {
    //三大核心参数
    private static String apiUrl = "https://sms_developer.zhenzikj.com";
    private static String appId = "110008";
    private static String appSecret = "78d9c59d-93e5-4ab5-aebd-ca9ab012edd8";


    public static String senSms(String phoneNum, String carNo) {
        ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);
        Map<String, Object> params = new HashMap<String, Object>();
        //设置接收短信的电话号码
        params.put("number", phoneNum);
        //设置短信模板
        params.put("templateId", "6956");
        //设置对应占位符中需要填入的字符
        String[] templateParams = new String[1];
        templateParams[0] = carNo;
        params.put("templateParams", templateParams);
        String result = null;
        try {
            //发送短信    返回值是一个json字符串   {"code":0,"data":"发送成功"}
            result = client.send(params);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result;
        }
    }
}
